﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace ZOIL.DataBackend
{
    /// <summary>
    /// Interaction logic for DataBackendSelectionDialog2.xaml
    /// </summary>
    public partial class DataBackendChooser : Window
    {
        #region properties

        public CollectionConnectionBase DatabaseConnection { get; private set; }

        #endregion

        public DataBackendChooser()
        {
            InitializeComponent();

            Loaded += OnLoaded;
        }

        void OnLoaded(object sender, RoutedEventArgs e)
        {
            CenterDialogToMainWindow();
        }

        private void CenterDialogToMainWindow()
        {
            var application = Application.Current;
            var mainWindow = application.MainWindow;
            Left = mainWindow.Left + (mainWindow.Width - ActualWidth) / 2;
            Top = mainWindow.Top + (mainWindow.Height - ActualHeight) / 2;
        }

        private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Console.WriteLine(DataBackendList.SelectedItem);

            DatabaseConnection = DataBackendList.SelectedItem as CollectionConnectionBase;

            DialogResult = true;
        }
    }
}
